<template>
  <Container class="store-list">
    <HeadFormItem
      slot="header"
      :list="list"
      @onSearchBtnClick="onSearchBtnClick"
    />
    <Tabs v-model="tab">
      <TabPane label="门店基础信息列表" name="tab1">
        <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
          @onSelectionChange="onSelectionChange"
        />
      </TabPane>
    </Tabs>
    
  </Container>
</template>
<script>
import StoreListData from './list/StoreListData'
import HeadFormItem from './list/HeadFormItem'
import SelectSearch from '@/components/SelectSearch'
import homeTable from '@/components/homeTable'

import { clearEmpty } from '@/util'
export default {
  name: 'manage/store/list',
  components: {
    HeadFormItem,
    SelectSearch,
    homeTable,
  },
  data() {
    return {
      tab: "tab1",
      list: StoreListData,
      productIds: []
    };
  },
  mounted() {
    this.getData();
    this.$bus.$on('detailRow', this.signInfo)
    this.$bus.$on('baseRow', this.signBase)
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    onSearchBtnClick() {
      this.list.currentPage = 1;
      this.getData();
    },
    signInfo(row) {
      this.$router.push({
        name: 'manage/store/info',
        query: {
          id: row.contractId
        }
      })
    },
    signBase(row) {
      this.$router.push({
        name: 'manage/store/base',
        query: {
          id: row.id
        }
      })
    },
    resignStore() {
      this.$refs.storeResign.openModal()
    },
    onChangeOwner() {
      this.$refs.supplerBind.openModal()
    },
    getData() {
      this.productIds = [];
      this.list.status = "loading";
     
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        ...this.list.form
      };
      if(param.auditStatus !== '') param.auditStatus = Number(param.auditStatus)
      param = clearEmpty(param)
      this.$jsonPost("/contract_store/page_store", param).then(data => {
          this.list.data = [];
          this.list.totalItem = Number(data.total);
          this.list.data = (data.records || []).map(item => {
            const { contractId, storeDTO } = item
            return Object.assign(storeDTO, {contractId})
          })
          this.list.status = "pass";
        })
        .catch(() => {
          this.list.status = "error";
        });
    },
    onSelectionChange(selection) {
      this.productIds = (selection || []).map(item => item.id);
    },
    onPageChange(number) {
      this.list.currentPage = number;
      this.getData();
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.getData();
    },
    onRefresh() {
      this.getData();
    },
    onExport() {
      this.$Message.info('导出')
    },
  },
  watch: {
  }
};
</script>
